Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix reimplemented-operator (FURB118) #4408

Merged
merged 3 commits into from
Sep 28, 2024

Conversation

echoix
Copy link
Member

@echoix echoix commented Sep 28, 2024

Ruff rule: https://docs.astral.sh/ruff/rules/reimplemented-operator/

Replaced lambdas with operator.itemgetter() or operator.add(). These are implemented more efficiently in C and have a Python fallback. An answer on Stcak Overflow shows how sorted() and min() with a key using itemgetter can be 10-15% or 20-60% faster (on Python 3.6).

I couldn't get a definitive answer, but some articles I've read explain that these functions, like itemgetter, can be pickable (requirement for being usable in multiprocessing on Windows/macOS and for Python 3.14), while lambdas are not (as the functions are pickled by name, and lambdas are anonymous and have the same name).

Ruff rule: https://docs.astral.sh/ruff/rules/reimplemented-operator/

Replaced lambdas with `operator.itemgetter()` or `operator.add()`. These are implemented more efficiently in C and have a Python fallback.
@echoix echoix added this to the 8.5.0 milestone Sep 28, 2024
@github-actions github-actions bot added GUI wxGUI related vector Related to vector data processing Python Related code is in Python libraries module docs general labels Sep 28, 2024
@echoix echoix enabled auto-merge (squash) September 28, 2024 20:41
@echoix echoix merged commit 0ea5e37 into OSGeo:main Sep 28, 2024
27 checks passed
@echoix echoix deleted the fix-FURB118-reimplemented-operator branch September 28, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs general GUI wxGUI related libraries module Python Related code is in Python vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants